<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<!-- <script src="https://cdn.staticfile.net/crypto-js/4.2.0/sha256.min.js"></script> -->
<script src="https://cdn.staticfile.net/crypto-js/4.2.0/crypto-js.min.js"></script>

<body>

  <script>

    const urlPart =
      "https://oapi.dingtalk.com/robot/send?access_token=b6eb822108a8e6053138c4ce3e6c422e322a82253a88d56c750c21f9753e0fe0";

    const timestamp = `${Date.now()}`;

    function generateDingTalkSign() {
      const secret =
        "SEC2fe7caaf3dd1ae059102f79b40c1877d0788c5055a36c1d21af903f1bd6acf91";



      const stringToSign = `${timestamp}\n${secret}`;
      var hash = CryptoJS.HmacSHA256(stringToSign, CryptoJS.enc.Hex.parse(secret));
      return hash.toString(CryptoJS.enc.Hex);
    }


    // 消息内容（假设为JSON格式）
    const message = {
      msgtype: "text",
      text: {
        content: "Hello, this is a signed message!",
      },
    };

    const urlWithSign = `${urlPart}&timestamp=${timestamp}&sign=${encodeURIComponent(
      generateDingTalkSign()
    )}`;

    fetch(urlWithSign, { method: 'post', body: JSON.stringify(message) }).then(response => {
      console.log("消息发送成功", response);
    }).catch((error) => {
      console.error("消息发送失败", error);
    });
  </script>
</body>

</html>